package com.dm0858.bianmin.mine.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager;

import android.os.Bundle;
import android.view.View;

import com.dm0858.bianmin.R;
import com.dm0858.bianmin.databinding.ActivityMyReleaseLayoutBinding;
import com.dm0858.bianmin.mine.adapter.MyReleaseRecyclerViewAdapter;
import com.dm0858.bianmin.mine.base.BaseActivity;
import com.dm0858.bianmin.mine.bean.MyReleaseBeanData;
import com.dm0858.bianmin.mine.viewmodel.MyReleaseViewModel;

import java.util.List;

/**
 * @description 我的发布
 * @author 迪迪丶Sir
 * @e-mail asd969709719@qq.com
 * @since 2020-05-02
 **/
public class MyReleaseActivity extends BaseActivity implements View.OnClickListener {

    private ActivityMyReleaseLayoutBinding binding;

    private MyReleaseViewModel viewModel;

    private MyReleaseRecyclerViewAdapter adapter;

    private int page = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this,R.layout.activity_my_release_layout);
        binding.setOnClick(this);
        initData();
    }

    @Override
    protected void initData() {
        viewModel = new ViewModelProvider(this).get(MyReleaseViewModel.class);
        viewModel.userArticle(1);
        viewModel.getReleaseList().observe(this, dataBeans -> {
            if (dataBeans == null) return;
            if (adapter == null) adapter = new MyReleaseRecyclerViewAdapter(this,R.layout.adapter_my_release_item_layout,dataBeans);
            binding.recyclerview.setLayoutManager(new GridLayoutManager(this,1));
            binding.recyclerview.setAdapter(adapter);
        });


    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                onBackPressed();
                break;
        }
    }
}